"""
知识库文件收藏相关数据模型
"""
from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field  # pyright: ignore[reportMissingImports]
from bson import ObjectId  # pyright: ignore[reportMissingImports]
from app.models.base import PyObjectId


class KnowledgeFavorite(BaseModel):
    """知识库文件收藏模型"""
    id: Optional[PyObjectId] = Field(default=None, alias="_id")
    file_id: PyObjectId = Field(..., description="文件ID")
    user_id: PyObjectId = Field(..., description="用户ID")
    created_at: datetime = Field(default_factory=datetime.utcnow, description="创建时间")

    class Config:
        populate_by_name = True
        arbitrary_types_allowed = True
        json_encoders = {
            ObjectId: str,
            datetime: lambda v: v.isoformat()
        }

